<?php
session_start();
$UserID = trim($_SESSION['user_id']);
if($UserID == "")
{
	$UserID = session_id();
	$_SESSION['user_id'] = $UserID;
}
include("../application/base_class.php");
$base_obj = new BaseClass();

$id=$_GET['id'];

 $data = $base_obj->exec_query("delete from composedocument where username='".$_SESSION['user_id']."' and id='$id'");
 echo $data;
 ////////////////////////// ExIT CODE HERE ///////////////////////////////
 exit();
 ////////////////////////// ExIT CODE HERE ///////////////////////////////
?>


<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="borders">
      <?php
	    
		
		$citationListForJS = "\"[{";
		$citationListToInsertForJS = "\"";
     
	  $list =$base_obj->exec_query("select * from composedocument where username='".$_SESSION['user_id']."' and types!='compose' order by id DESC");
	  $listCount = 1;
	  while($work = mysql_fetch_array($list)){
	  ?>
      <tr>
        <td colspan="3" height="5" align="left" valign="middle"></td>
      </tr>
      <tr>
        <td width="9%" align="center" valign="top" style="padding-top:10px;" class="font12">&bull;</td>
        <td width="79%" align="left" valign="middle" class="font12" style="font-size:11px;">
        <?php 
		$citationList = "";
		$string = $work['firstname'];
		echo $work['lastname'].", ".$string[0]."., ";
		$exp = explode(",",$work['author']);
		$cut = count($exp);
		$citationList .= $work['lastname'];
			$result = "";
			for($i=0;$i<$cut;$i++){
				$spt = explode("`",$exp[$i]);
				//echo $spt[0];
				if($spt[0]!=""){
					$comm = (($cut-2)>=$i)? "," : "";
					$ands = (($cut-2)>=$i)? "" : "";
					$lists = $spt[0];
					$last = ($cut-1);
					if($i>4 && $last>$i)
					$result .= ' ... ';
					else
					$result .= $ands.''.$spt[1].", ".substr($lists,0,1).".".$comm;				
				}
				if(trim($spt[1]) != "")	$citationList .= ",".$spt[1];
				
			}
			//echo "<p><br>CitationList ".$citationList."<br><p>";
		
		
			$TotalAllowableAuthorsForFirstFormat = 5;
			$TotalAllowableAuthorsForSecondFormat = 2;			
			$Authors = explode(",",$citationList);
			$TotalAuthors = count($Authors);
			//echo "<p><br>TotalAuthors ".$TotalAuthors."<br><p>";
			if($TotalAuthors > 0){
				$citationListFirstFormat = $Authors[0];
				$citationListSecondFormat = "(".$Authors[0];
				if($TotalAuthors == 1) $citationListSecondFormat .= ",";
				if($TotalAuthors <= $TotalAllowableAuthorsForFirstFormat){		
					for($i=1;$i<$TotalAuthors;$i++){
						if($i == ($TotalAuthors-1)){
							$citationListFirstFormat .= " and ";
						}else{
							$citationListFirstFormat .= ", ";
						}
						$citationListFirstFormat .= $Authors[$i];
					}
					$citationListFirstFormat .= " (".$work['pyear'].", p.)";
				}else{
					$citationListFirstFormat .= " et al.(".$work['pyear'].", p.)";
				}
				//echo "<p><br>CitationListFirstFormat ".$citationListFirstFormat."<p>";
				if($TotalAuthors <= $TotalAllowableAuthorsForSecondFormat){
					for($i=1;$i<$TotalAuthors;$i++){
						if($i == ($TotalAuthors-1)){
							$citationListSecondFormat .= " & ";
						}else{
							$citationListSecondFormat .= ", ";
						}
						$citationListSecondFormat .= $Authors[$i]." ";
					}
					$citationListSecondFormat .= " ".$work['pyear'].", p.)";
				}else{
					$citationListSecondFormat .= " et al.".$work['pyear'].", p.)";
				}
				//echo "<p><br>CitationListSecondFormat ".$citationListSecondFormat."<p>";
			}
		$dois = ($work['digitalobject']!="")? "doi:" : "";
		echo $result;
		?> <?php echo " (".$work['pyear']."). ".$work['booktitle']?>. <i><?php echo $work['journaltitle']?></i>, <?php echo $work['publisher']?> <i><?php echo $work['edition']."</i>(".$work['issuenumber']."), ".$work['pagenumber'].". ".$dois.$work['digitalobject'];?>
        </td>
     	<td width="12%" align="center" valign="middle" class="font12" style="font-size:11px;">
        <a href="index.php?page=assignment_manager&_e=<?php echo $work['id'];?>&_t=<?php echo $work['types']?>">
        <img src="http://www.studysage.com.au/images/edit.jpg" border="0" title="EDIT" alt="EDIT" /></a><br /><br />
        <a href="javascript:void(0);" onclick="if(confirm('Are you sure want to delete this?'))Del_Refernce('<?php echo $work['id'];?>');">
        <img src="http://www.studysage.com.au/images/delete.jpg" border="0" title="DELETE" alt="DELETE" /></a>
        </td>
      </tr>
      <tr>
        <td colspan="3" height="5" align="left" valign="middle"></td>
      </tr>
      <tr>
        <td colspan="3" height="1" align="left" valign="middle" bgcolor="#E4E4E4"></td>
      </tr>
	  <?php 
			$citationListForJS .= "'citation_".$listCount."':'".$citationListFirstFormat."',";
			$citationListToInsertForJS .= str_replace(",","_S_S_",$citationListFirstFormat).",";
			$listCount++;
			$citationListForJS .= "'citation_".$listCount."':'".$citationListSecondFormat."',";
			$citationListToInsertForJS .= str_replace(",","_S_S_",$citationListSecondFormat).",";
			$listCount++;
	  }
	  $citationListForJS = substr($citationListForJS,0,(strlen($citationListForJS)-1));
		$citationListToInsertForJS = substr($citationListToInsertForJS,0,(strlen($citationListToInsertForJS)-1));
		$citationListForJS .= "}]\"";
		$citationListToInsertForJS .= "\"";
		//echo "<p><br>CitationListDropDown ".$citationListForJS."<p>";
		//echo "<p><br>CitationList ".$citationListToInsertForJS."<p>";
		echo "<script>citationList = ".$citationListForJS.";citationToInsert = ".$citationListToInsertForJS.";</script>";
	  ?>  
    </table>